package ScalaStudy.chapter02

import ScalaStudy.chapter01.Student
import firrtl.ir.Print
import treadle.executable.PrintInfo

import scala.runtime.Nothing$

object Test07_DataType {
  def main(args: Array[String]): Unit = {
    //（1）整数类型
    val a1: Byte = 127
    val a2: Byte = -128
//    val a3: Byte = 128    //error

    val a3 = 12             //默认整数类型为int
    val a4 = 1212121212121L //长整型定义

    //（2）强制类型转换
    val b1:Byte = 10
    val b2:Byte = (b1 + 20).toByte
    println(b2)

    //（3）浮点类型
    val f1 = 1.2345         //默认Double
    val f2 = 1.2345f        //末尾加f，定义成Float

    //（4）字符类型
    val c1: Char = 'a'
    println(c1)

    val c2: Char = '9'
    println(c2)

    //特殊字符
    val c3: Char = '\t'     //制表符
    val c4: Char = '\n'     //换行符
    println("wang" + c3 + "qiang")
    println("wang" + c4 + "qiang")

    //转义字符
    val c5 = '\\'           //表示\自身
    val c6 = '\"'           //表示“自身
    println("wang" + c5 + "qiang")
    println("wang" + c6 + "qiang")

    //字符变量底层保存ASCII码
    val i1: Int = c1
    val i2: Int = c2
    println(i1)
    println(i2)

    val c7: Char = (i1 + 1).toChar
    println(c7)
    val c8: Char = (i2 - 1).toChar
    println(c8)

    //（5）布尔类型
    val isTure: Boolean = true
    println(isTure)

    //（6）空类型

    //6.1空值

    def m1(): Unit = {
      println("6.1 m1将被执行")
    }

    val a = m1()
    println(a)

    //6.2 空引用Null
    var student: Student = new Student("wq", 20)
    student = null
    println(s"6.2 ${student}")

    //6.3 Nothing
    def m2(n: Int): Int = {
      if (n == 0)                            //如果n为0 则抛出异常
        throw new NullPointerException()
      else
        return n
    }

    val b = m2(2)
    println(b)



  }
}
